﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.RenderTextureDescriptor
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using UnityEngine.Experimental.Rendering;
using UnityEngine.Internal;
using UnityEngine.Rendering;

#nullable disable
namespace UnityEngine
{
  /// <summary>
  ///   <para>This struct contains all the information required to create a RenderTexture. It can be copied, cached, and reused to easily create RenderTextures that all share the same properties. Avoid using the default constructor as it does not initialize some flags with the recommended values.</para>
  /// </summary>
  public struct RenderTextureDescriptor
  {
    private GraphicsFormat _graphicsFormat;
    private RenderTextureCreationFlags _flags;

    /// <summary>
    ///   <para>The width of the render texture in pixels.</para>
    /// </summary>
    public int width { get; set; }

    /// <summary>
    ///   <para>The height of the render texture in pixels.</para>
    /// </summary>
    public int height { get; set; }

    /// <summary>
    ///         <para>The multisample antialiasing level for the RenderTexture.
    /// 
    /// Additional resources: RenderTexture.antiAliasing.</para>
    ///       </summary>
    public int msaaSamples { get; set; }

    /// <summary>
    ///   <para>Volume extent of a 3D render texture.</para>
    /// </summary>
    public int volumeDepth { get; set; }

    /// <summary>
    ///   <para>User-defined mipmap count.</para>
    /// </summary>
    public int mipCount { get; set; }

    /// <summary>
    ///   <para>The color format for the RenderTexture. You can set this format to None to achieve depth-only rendering.</para>
    /// </summary>
    public GraphicsFormat graphicsFormat
    {
      get => this._graphicsFormat;
      set
      {
        this._graphicsFormat = value;
        this.SetOrClearRenderTextureCreationFlag(GraphicsFormatUtility.IsSRGBFormat(value), RenderTextureCreationFlags.SRGB);
        this.depthBufferBits = this.depthBufferBits;
      }
    }

    /// <summary>
    ///         <para>The format of the stencil data that you can encapsulate within a RenderTexture.
    /// 
    /// Specifying this property creates a stencil element for the RenderTexture and sets its format.
    /// This allows for stencil data to be bound as a Texture to all shader types for the platforms that support it.
    /// This property does not specify the format of the stencil buffer, which is constrained by the depth buffer format specified in RenderTexture.depth.
    /// 
    /// Currently, most platforms only support R8_UInt (DirectX11, DirectX12), while PS4 also supports R8_UNorm.</para>
    ///       </summary>
    public GraphicsFormat stencilFormat { get; set; }

    /// <summary>
    ///   <para>The desired format of the depth/stencil buffer.</para>
    /// </summary>
    public GraphicsFormat depthStencilFormat { get; set; }

    /// <summary>
    ///   <para>The format of the RenderTarget is expressed as a RenderTextureFormat. Internally, this format is stored as a GraphicsFormat compatible with the current system (see SystemInfo.GetCompatibleFormat). Therefore, if you set a format and immediately get it again, it may return a different result from the one just set.</para>
    /// </summary>
    public RenderTextureFormat colorFormat
    {
      get
      {
        return this.graphicsFormat != 0 ? GraphicsFormatUtility.GetRenderTextureFormat(this.graphicsFormat) : (this.shadowSamplingMode != ShadowSamplingMode.None ? RenderTextureFormat.Shadowmap : RenderTextureFormat.Depth);
      }
      set
      {
        this.graphicsFormat = SystemInfo.GetCompatibleFormat(GraphicsFormatUtility.GetGraphicsFormat(value, this.sRGB), FormatUsage.Render);
      }
    }

    /// <summary>
    ///   <para>This flag causes the render texture uses sRGB read/write conversions.</para>
    /// </summary>
    public bool sRGB
    {
      get => GraphicsFormatUtility.IsSRGBFormat(this.graphicsFormat);
      set
      {
        this.graphicsFormat = !value || QualitySettings.activeColorSpace != ColorSpace.Linear || this.colorFormat == RenderTextureFormat.R8 || this.colorFormat == RenderTextureFormat.RG16 ? GraphicsFormatUtility.GetLinearFormat(this.graphicsFormat) : GraphicsFormatUtility.GetSRGBFormat(this.graphicsFormat);
      }
    }

    /// <summary>
    ///   <para>The precision of the render texture's depth buffer in bits (0, 16, 24 and 32 are supported).</para>
    /// </summary>
    public int depthBufferBits
    {
      get => GraphicsFormatUtility.GetDepthBits(this.depthStencilFormat);
      set
      {
        this.depthStencilFormat = RenderTexture.GetDepthStencilFormatLegacy(value, this.graphicsFormat);
      }
    }

    /// <summary>
    ///         <para>Dimensionality (type) of the render texture.
    /// 
    /// Additional resources: RenderTexture.dimension.</para>
    ///       </summary>
    public TextureDimension dimension { get; set; }

    /// <summary>
    ///         <para>Determines how the RenderTexture is sampled if it is used as a shadow map.
    /// 
    /// Additional resources: ShadowSamplingMode for more details.</para>
    ///       </summary>
    public ShadowSamplingMode shadowSamplingMode { get; set; }

    /// <summary>
    ///   <para>If this RenderTexture is a VR eye texture used in stereoscopic rendering, this property decides what special rendering occurs, if any. Instead of setting this manually, use the value returned by XR.XRSettings.eyeTextureDesc|eyeTextureDesc or other VR functions returning a RenderTextureDescriptor.</para>
    /// </summary>
    public VRTextureUsage vrUsage { get; set; }

    /// <summary>
    ///   <para>A set of RenderTextureCreationFlags that control how the texture is created.</para>
    /// </summary>
    public RenderTextureCreationFlags flags => this._flags;

    /// <summary>
    ///   <para>The render texture memoryless mode property.</para>
    /// </summary>
    public RenderTextureMemoryless memoryless { get; set; }

    [ExcludeFromDocs]
    public RenderTextureDescriptor(int width, int height)
      : this(width, height, RenderTextureFormat.Default)
    {
    }

    [ExcludeFromDocs]
    public RenderTextureDescriptor(int width, int height, RenderTextureFormat colorFormat)
      : this(width, height, colorFormat, 0)
    {
    }

    [ExcludeFromDocs]
    public RenderTextureDescriptor(
      int width,
      int height,
      RenderTextureFormat colorFormat,
      int depthBufferBits)
      : this(width, height, colorFormat, depthBufferBits, Texture.GenerateAllMips)
    {
    }

    [ExcludeFromDocs]
    public RenderTextureDescriptor(
      int width,
      int height,
      GraphicsFormat colorFormat,
      int depthBufferBits)
      : this(width, height, colorFormat, depthBufferBits, Texture.GenerateAllMips)
    {
    }

    [ExcludeFromDocs]
    public RenderTextureDescriptor(
      int width,
      int height,
      RenderTextureFormat colorFormat,
      int depthBufferBits,
      int mipCount)
      : this(width, height, colorFormat, depthBufferBits, mipCount, RenderTextureReadWrite.Linear)
    {
    }

    /// <summary>
    ///   <para>Create a RenderTextureDescriptor with default values, or a certain width, height, and format.</para>
    /// </summary>
    /// <param name="width">Width of the RenderTexture in pixels.</param>
    /// <param name="height">Height of the RenderTexture in pixels.</param>
    /// <param name="colorFormat">The color format for the RenderTexture.</param>
    /// <param name="depthStencilFormat">The depth stencil format for the RenderTexture.</param>
    /// <param name="depthBufferBits">The number of bits to use for the depth buffer.</param>
    /// <param name="mipCount">Amount of mips to allocate for the RenderTexture.</param>
    /// <param name="readWrite">How color space conversions are applied on texture read/write.</param>
    public RenderTextureDescriptor(
      int width,
      int height,
      [DefaultValue("RenderTextureFormat.Default")] RenderTextureFormat colorFormat,
      [DefaultValue("0")] int depthBufferBits,
      [DefaultValue("Texture.GenerateAllMips")] int mipCount,
      [DefaultValue("RenderTextureReadWrite.Linear")] RenderTextureReadWrite readWrite)
    {
      GraphicsFormat compatibleFormat = SystemInfo.GetCompatibleFormat(GraphicsFormatUtility.GetGraphicsFormat(colorFormat, readWrite), FormatUsage.Render);
      this = new RenderTextureDescriptor(width, height, compatibleFormat, RenderTexture.GetDepthStencilFormatLegacy(depthBufferBits, colorFormat), mipCount);
    }

    [ExcludeFromDocs]
    public RenderTextureDescriptor(
      int width,
      int height,
      GraphicsFormat colorFormat,
      int depthBufferBits,
      int mipCount)
      : this()
    {
      this._flags = RenderTextureCreationFlags.AutoGenerateMips | RenderTextureCreationFlags.AllowVerticalFlip;
      this.width = width;
      this.height = height;
      this.volumeDepth = 1;
      this.msaaSamples = 1;
      this.graphicsFormat = colorFormat;
      this.depthStencilFormat = RenderTexture.GetDepthStencilFormatLegacy(depthBufferBits, colorFormat);
      this.mipCount = mipCount;
      this.dimension = TextureDimension.Tex2D;
      this.shadowSamplingMode = ShadowSamplingMode.None;
      this.vrUsage = VRTextureUsage.None;
      this.memoryless = RenderTextureMemoryless.None;
    }

    [ExcludeFromDocs]
    public RenderTextureDescriptor(
      int width,
      int height,
      GraphicsFormat colorFormat,
      GraphicsFormat depthStencilFormat)
      : this(width, height, colorFormat, depthStencilFormat, Texture.GenerateAllMips)
    {
    }

    [ExcludeFromDocs]
    public RenderTextureDescriptor(
      int width,
      int height,
      GraphicsFormat colorFormat,
      GraphicsFormat depthStencilFormat,
      int mipCount)
      : this()
    {
      this._flags = RenderTextureCreationFlags.AutoGenerateMips | RenderTextureCreationFlags.AllowVerticalFlip;
      this.width = width;
      this.height = height;
      this.volumeDepth = 1;
      this.msaaSamples = 1;
      this.graphicsFormat = colorFormat;
      this.depthStencilFormat = depthStencilFormat;
      this.mipCount = mipCount;
      this.dimension = TextureDimension.Tex2D;
      this.shadowSamplingMode = ShadowSamplingMode.None;
      this.vrUsage = VRTextureUsage.None;
      this.memoryless = RenderTextureMemoryless.None;
    }

    private void SetOrClearRenderTextureCreationFlag(bool value, RenderTextureCreationFlags flag)
    {
      if (value)
        this._flags |= flag;
      else
        this._flags &= ~flag;
    }

    /// <summary>
    ///         <para>Render texture has mipmaps when this flag is set.
    /// 
    /// Additional resources: RenderTexture.useMipMap.</para>
    ///       </summary>
    public bool useMipMap
    {
      get => (this._flags & RenderTextureCreationFlags.MipMap) != 0;
      set => this.SetOrClearRenderTextureCreationFlag(value, RenderTextureCreationFlags.MipMap);
    }

    /// <summary>
    ///   <para>Mipmap levels are generated automatically when this flag is set.</para>
    /// </summary>
    public bool autoGenerateMips
    {
      get => (this._flags & RenderTextureCreationFlags.AutoGenerateMips) != 0;
      set
      {
        this.SetOrClearRenderTextureCreationFlag(value, RenderTextureCreationFlags.AutoGenerateMips);
      }
    }

    /// <summary>
    ///         <para>Enable random access write into this render texture on Shader Model 5.0 level shaders.
    /// 
    /// Additional resources: RenderTexture.enableRandomWrite.</para>
    ///       </summary>
    public bool enableRandomWrite
    {
      get => (this._flags & RenderTextureCreationFlags.EnableRandomWrite) != 0;
      set
      {
        this.SetOrClearRenderTextureCreationFlag(value, RenderTextureCreationFlags.EnableRandomWrite);
      }
    }

    /// <summary>
    ///   <para>If true and msaaSamples is greater than 1, the render texture will not be resolved by default.  Use this if the render texture needs to be bound as a multisampled texture in a shader.</para>
    /// </summary>
    public bool bindMS
    {
      get => (this._flags & RenderTextureCreationFlags.BindMS) != 0;
      set => this.SetOrClearRenderTextureCreationFlag(value, RenderTextureCreationFlags.BindMS);
    }

    internal bool createdFromScript
    {
      get => (this._flags & RenderTextureCreationFlags.CreatedFromScript) != 0;
      set
      {
        this.SetOrClearRenderTextureCreationFlag(value, RenderTextureCreationFlags.CreatedFromScript);
      }
    }

    internal bool enableHWSharable
    {
      get => (this._flags & RenderTextureCreationFlags.APISharable) != 0;
      set
      {
        this.SetOrClearRenderTextureCreationFlag(value, RenderTextureCreationFlags.APISharable);
      }
    }

    /// <summary>
    ///         <para>Set to true to enable dynamic resolution scaling on this render texture.
    /// 
    /// Additional resources: RenderTexture.useDynamicScale.</para>
    ///       </summary>
    public bool useDynamicScale
    {
      get => (this._flags & RenderTextureCreationFlags.DynamicallyScalable) != 0;
      set
      {
        this.SetOrClearRenderTextureCreationFlag(value, RenderTextureCreationFlags.DynamicallyScalable);
      }
    }
  }
}
